package com.springboot.controller;

import com.springboot.Service.AdminService;
import com.springboot.entity.Admin;
import com.springboot.utils.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
@Api(value = "提供了用户登录、注册、查询、增加等相关的接口",tags = "读者管理")
@CrossOrigin
@RestController
public class AdminController {
    @Resource
    private AdminService adminService;

    @ResponseBody //异步请求
    @ApiOperation("老师登录接口")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(dataType = "string",name = "username",value="用户名",required = true),
                    @ApiImplicitParam(dataType = "string",name = "password",value="密码",required = true)
            }
    )
    @RequestMapping(value = "/login",method =  RequestMethod.GET)
    public ResultVO login(String username, String password){
        return adminService.login(username, password);
    }

    @RequestMapping(value = "/adminList",method = RequestMethod.GET)
    @ApiOperation("查询分页接口")
    public ResultVO showList(String name, @RequestParam(defaultValue = "1") int pageNum) {
        return adminService.AdminList(name, pageNum);
    }
    @RequestMapping(value = "/addAdmin",method = RequestMethod.POST)
    @ApiOperation("读者新增接口")
    public ResultVO addAdmin(Admin admin){
        return adminService.addAdmin(admin);
    }
    @RequestMapping(value = "/deleteAdmin",method = RequestMethod.GET)
    @ApiOperation("用户删除接口")
    public ResultVO deleteAdmin(long aid){
        return adminService.deleteAdmin(aid);
    }
}
